package model;

import java.util.ArrayList;

import model.UserGroup;
/**
 * This Class is a singleton that holds the user permissions
 * @author Tomer Elkayam
 */

public class UserPermissions
{
	private static UserPermissions up;
	private  int currentUserID;
	private ArrayList<UserGroup> userGroups;
	private ArrayList<Button> userButtons;
	
	protected UserPermissions(int currentUserID , ArrayList<UserGroup> userGroups , ArrayList<Button> userButtons)
	{
		this.currentUserID = currentUserID;
		this.userGroups = userGroups;
		this.userButtons = userButtons;
	}
	
	public static synchronized UserPermissions getInstance(int currentUserID , ArrayList<UserGroup> userGroups , ArrayList<Button> userButtons)
	{
		if(up==null)
			up = new UserPermissions(currentUserID ,userGroups, userButtons);
		return up;
	}
	
	public int getCurrUserID()
	{
		return this.currentUserID;
	}

	public ArrayList<UserGroup> getUserGroups()
	{
		return userGroups;
	}
	public ArrayList<Button> getUserButtons() 
	{
		return userButtons;
	}
	
	public void setGroupButtons(ArrayList<Button> userButtons) 
	{
		this.userButtons = userButtons;
	}
	
	public boolean userHasGroup(String groupName)
	{ 
		ArrayList<UserGroup> ug = up.getUserGroups();
		for (int i = 0; i < ug.size(); i++) 
			if(ug.get(i).getGroupName().equals(groupName))
				return true;
	
		return false;
	}
}
